package com.example.service.impl;

import com.example.dao.UserDao;
import com.example.entity.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
//@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;
    @Override
    public User getUserById(int uid) {
        return userDao.findById(uid);
    }

    @Override
    public List<User> getAllUser() {
        return userDao.findAll();
    }

    @Override
    public boolean addUser(User user) {
        return userDao.insert(user) > 0;
    }

    @Override
    public boolean updateUser(User user) {
        return userDao.update(user) > 0;
    }

    @Override
    public boolean deleteUser(Integer uid) {
        return userDao.delete(uid) > 0;
    }

    @Override
    public User findByNameAndPassword(String username, String password) {
        return userDao.findByNameAndPassword(username,password);
    }

    @Override
    public List<User> searchByUsername(String username) {
        return userDao.searchByUsername(username);

    }

    //修改个人信息
    @Override
    public User findByUid(Integer uid) {
        return userDao.findByUid(uid);
    }

    @Override
    public int updateScore(int uid, int score) {
        return userDao.updateScore(uid,score);
    }
}
